package com.stu.stusystem.controller.system;

import com.github.pagehelper.PageInfo;
import com.stu.stusystem.common.ApiResult;
import com.stu.stusystem.common.OffsetPage;
import com.stu.stusystem.service.system.MenuService;
import com.stu.stusystem.service.system.dto.MenuDTO;
import com.stu.stusystem.service.system.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: cxt
 * @time: 2021/3/29
 */
@Api(tags = "菜单管理")
@RestController
@RequestMapping("/menu")
public class MenuController {

    private MenuService menuService;

    @ApiOperation("分页查询")
    @GetMapping("/get")
    public PageInfo<MenuVO> getMenuPage(OffsetPage query,String name) {
        return this.menuService.getMenuPage(query,name);
    }

    @ApiOperation("修改菜单")
    @PutMapping("/update")
    public ApiResult<String> updateMenu(@RequestBody MenuDTO dto) {
        this.menuService.updateMenu(dto);
        return ApiResult.success();
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/delete")
    public ApiResult<String> deleteMenu(@RequestParam("id") String id) {
        this.menuService.deleteMenu(id);
        return ApiResult.success();
    }

    @ApiOperation("新增菜单")
    @PostMapping("/add")
    public ApiResult<String> saveMenu(@RequestBody MenuDTO dto) {
        this.menuService.saveMenu(dto);
        return ApiResult.success();
    }

    @ApiOperation("查询树形菜单")
    @GetMapping("/get/treeMenu")
    public List<Object> getTreeMenu(){
        return this.menuService.getTreeMenu();
    }

    @Autowired
    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }
}
